package com.coinland.study.presenter;

import com.coinland.study.base.BasePresenter;
import com.coinland.study.contract.LoadLottieContract;
import com.coinland.study.model.LoadLottieModel;

import java.io.IOException;

import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.Response;

/**
 * 类描述:  加载Lottie json动画
 * 创建人:  shenZ
 * 创建时间: 2019/8/26
 * 联系方式: 252079249@qq.com
 * 修改时间: 2019/8/26
 */
public class LoadLottiePresenter extends BasePresenter<LoadLottieContract.View> implements LoadLottieContract.Presenter {


    LoadLottieModel  model;

    public LoadLottiePresenter(){
        model = new LoadLottieModel();
    }

    @Override
    public void loadLottie(String url) {
        //View是否绑定 如果没有绑定，就不执行网络请求
        if (!isViewAttached()) {
            return;
        }

        model.loadLottie(url).enqueue(new Callback() {
            @Override
            public void onFailure(Call call, IOException e) {
                mView.loadError(e);
            }


            @Override
            public void onResponse(Call call, Response response) {
                mView.loadSuccess(response);
            }
        });

    }
}
